# coding=utf8
# -*-coding:utf-8 -*-
import datetime


def obj_to_dicts(obj):
    d = {}
    field_names_list = obj.__dict__
    for field_name in field_names_list:
        if field_name == "_state":
            continue
        field_value = getattr(obj, field_name)
        if type(field_value) is datetime.date or type(field_value) is datetime.datetime:
            field_value = datetime.datetime.strftime(field_value, '%Y-%m-%d %H:%M:%S')
        d[field_name] = str(field_value)
    return d


def query_set_to_list(query_set):
    set_result = []
    for obj in query_set:
        dict = obj_to_dicts(obj)
        set_result.append(dict)
    return set_result
